home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / tex / dvivga9.arc / DVIVGA.C < prev    next >
C/C++ Source or Header  |  1988-10-22  |  17KB  |  619 lines

  1. /* latest revision Oct. 18, 1988 by JDM
  2.  
  3.  
  4.  
  5. /* -*-C-*- dvivga.c */
  6. /*-->dvivga*/
  7. /**********************************************************************/
  8. /******************************* dvivga *******************************/
  9. /**********************************************************************/
  10. #include "dvihead.h"
  11.  
  12.  
  13. /**********************************************************************/
  14. /************************  Device Definitions  ************************/
  15. /**********************************************************************/
  16.  
  17. /* All output-device-specific definitions go here.  This section must
  18. be changed when modifying a dvi driver for use on a new device */
  19.  
  20.  
  21. #undef  DEBUG
  22. #define DEBUG 1
  23. #undef   VGASCREEN
  24. #define  VGASCREEN       1        /* conditional compilation flag */
  25.  
  26.  
  27.  
  28.  
  29. #undef HIRES
  30. #define  HIRES          0        /* this is 72 dpi version  */
  31.  
  32. #define VERSION_NO    "2.10"        /* DVI driver version number */
  33.  
  34. #define  DEVICE_ID    "VGA Screen Previewer"
  35.                     /* this string is printed at runtime */
  36. #define OUTFILE_EXT    "vga"
  37.  
  38. #define  BYTE_SIZE        8        /* output file byte size */
  39.  
  40. #undef STDRES
  41. #define STDRES  0            /* 0 for low-resolution devices */
  42.  
  43. #define  XDPI           72
  44. #define  XPSIZE        8        /* horizontal paper size in inches */
  45. #define  XSIZE          640
  46. #define  YPSIZE         14
  47.  
  48.                     /* 2*HOST_WORD_SIZE */
  49.  
  50.  
  51.  
  52. #define  XWORDS        ((XSIZE + HOST_WORD_SIZE - 1)/HOST_WORD_SIZE)
  53.                     /* number of words in rows  */
  54.                     /* of bitmap array */
  55.  
  56. #define  YDPI        XDPI        /* vertical dots/inch */
  57. #define  YSIZE        (YDPI*YPSIZE)    /* number of vertical dots */
  58.  
  59. /* The printer bit map. */
  60.  
  61. #define XBIT XWORDS
  62. #define YBIT YSIZE
  63.  
  64. #undef  SEGMEM
  65. #define SEGMEM 1 
  66.  
  67. #define  MINM  0
  68.  
  69. int      firstlinepage, brokenprtpage;
  70. int      neednewpage, neednewbmap;
  71. double   newmagfact;
  72. int      first_picture = TRUE;
  73. int      maxm, nlines, oldvmode, displaycode ;
  74.  
  75. #include <bios.h>
  76. #include <dos.h>
  77. #include <conio.h>
  78.  
  79. UNSIGN32* bitmap[YBIT+1] =
  80. {
  81.     (UNSIGN32*)NULL    /* only first entry need be initialized */
  82. };
  83. #define BITMAP(y,x) (bitmap[y] + (UNSIGN16)(x))
  84.  
  85.  
  86. #include "main.h"
  87. #undef STDMAG
  88. #define STDMAG 550
  89.  
  90. #include "abortrun.h"
  91. #include "actfact.h"
  92. #include "alldone.h"
  93. #include "chargf.h"
  94. #include "charpk.h"
  95. #include "charpxl.h"
  96. #include "clrbmap.h"
  97. #include "clrrow.h"
  98. #include "dbgopen.h"
  99.  
  100. int  far        exfn();
  101.  
  102.  
  103. int far exfn()
  104. {
  105.     devterm();
  106.     exit(1);
  107. }
  108.  
  109.  
  110. /*-->devinit*/
  111. /**********************************************************************/
  112. /****************************** devinit *******************************/
  113. /**********************************************************************/
  114.  
  115. void
  116. devinit(argc,argv)        /* initialize device */
  117. int argc;
  118. char *argv[];
  119. {
  120.     (void)getbmap();
  121.  
  122. }
  123.  
  124. /*-->devterm*/
  125. /**********************************************************************/
  126. /****************************** devterm *******************************/
  127. /**********************************************************************/
  128.  
  129. void
  130. devterm()            /* terminate device */
  131. {
  132.    union REGS rg;
  133.    rg.x.ax = oldvmode;
  134.    if(!first_picture)int86(16,&rg,&rg);
  135. }
  136.  
  137. #include "dispchar.h"
  138. #include "dvifile.h"
  139. #include "dviinit.h"
  140. #include "dviterm.h"
  141. #include "fatal.h"
  142. #include "fillrect.h"
  143. #include "findpost.h"
  144. #include "fixpos.h"
  145. #include "fontfile.h"
  146. #include "fontsub.h"
  147.  
  148. void
  149. getbmap()                /* allocate bitmap array */
  150. {
  151.  
  152. static unsigned long huge basebit[ (long)XBIT * (long)(YBIT+2)];
  153. unsigned long *ibit;
  154. unsigned long i, j, k;
  155. unsigned y;
  156.     if (bitmap[0] == (UNSIGN32*)NULL) {
  157.  
  158.         for (y = 0; y <= (UNSIGN16)YBIT; ++y)
  159.         {
  160.             ibit = (unsigned long *) &basebit[ y  * XBIT ];
  161.                    /* UGH! fix up pointers to avoid segment overlap */
  162.             i = (unsigned long)ibit & (unsigned long)4;
  163.             j = (unsigned long)ibit & (unsigned long) 0x0000fff0L;
  164.             k = (unsigned long)ibit & (unsigned long) 0xffff0000L;
  165.             i += k + (j << 12);
  166.             bitmap[y] = (UNSIGN32*) i;
  167.         }
  168.     }
  169. }
  170.  
  171.  
  172.  
  173.  
  174. #include "getbytes.h"
  175. #include "getfntdf.h"
  176. #include "getpgtab.h"
  177. #include "inch.h"
  178. #include "initglob.h"
  179. #include "loadchar.h"
  180.  
  181. /*-->makechar*/
  182. /**********************************************************************/
  183. /****************************** makechar ******************************/
  184. /**********************************************************************/
  185.  
  186. char
  187. makechar(p,mask)
  188. UNSIGN32* p[];
  189. register UNSIGN32 mask;
  190. {
  191.  
  192. }
  193.  
  194. #include "movedown.h"
  195. #include "moveover.h"
  196. #include "moveto.h"
  197. #include "nosignex.h"
  198. #include "openfont.h"
  199. #include "option.h"
  200.  
  201. /*-->outline*/
  202. /**********************************************************************/
  203. /****************************** outline *******************************/
  204. /**********************************************************************/
  205.  
  206.  
  207. void
  208. outline(pline)
  209. char *pline;
  210. {
  211.  
  212. }
  213.  
  214. #include "outrow.h"
  215.  
  216. /*-->prtbmap*/
  217. /**********************************************************************/
  218. /****************************** prtbmap *******************************/
  219. /**********************************************************************/
  220. void prtbmap()
  221. {
  222. }
  223. #include "prtpage.h"
  224. #include "readfont.h"
  225. #include "readgf.h"
  226. #include "readpk.h"
  227. #include "readpost.h"
  228. #include "readpxl.h"
  229. #include "reldfont.h"
  230. #include "rulepxl.h"
  231. #include "setchar.h"
  232. #include "setfntnm.h"
  233. #include "setrule.h"
  234. #include "signex.h"
  235. #include "skgfspec.h"
  236. #include "skipfont.h"
  237. #include "skpkspec.h"
  238. #include "special.h"
  239. #include "strchr.h"
  240. #include "strcm2.h"
  241. #include "strid2.h"
  242. #include "strrchr.h"
  243. #include "tctos.h"
  244. #include "usage.h"
  245. #include "warning.h"
  246.  
  247.  
  248. void
  249. vgainit()        /* initialize device */
  250. {
  251.     union REGS rg;
  252.     char *envptr;
  253.  
  254.     *((unsigned long far *) (0x8c)) = (unsigned long)  exfn;
  255.     /*
  256.      * Oh my! That put a pointer to exfn() in the MS-DOS cntl-break
  257.      * interrupt vector! 
  258.      */
  259.  
  260.     rg.h.ah = 15;
  261.     int86(16,&rg,&rg);
  262.     oldvmode = rg.h.al;
  263.  
  264.     envptr = getenv("DVISCR");
  265.     if(strcmp(envptr,"EGAM") == 0 && envptr != NULL) displaycode = 5;
  266.     else if(strcmp(envptr,"EGAC") == 0 && envptr != NULL) displaycode = 4;
  267.     else if(strcmp(envptr,"VGAM") == 0 && envptr != NULL) displaycode = 7;
  268.     else if(strcmp(envptr,"VGAC") == 0 && envptr != NULL) displaycode = 30;
  269.     else {
  270.  
  271.         rg.x.ax = 0x1a00;
  272.         int86(16,&rg,&rg);
  273.         if(rg.h.al == 0x1a) {
  274.            displaycode = rg.h.bl;
  275.         } else {
  276.            rg.h.ah = 0x12;
  277.            rg.h.bl = 16;
  278.            int86(16,&rg,&rg);
  279.            if(rg.h.bl == 16) {
  280.                displaycode = 0;
  281.            } else {
  282.                if (oldvmode == 7) displaycode = 5;
  283.                else displaycode = 4;
  284.            }
  285.         }
  286.     }
  287.     switch (displaycode) {
  288.        case 4:
  289.            rg.x.ax = 16;
  290.            maxm =  YBIT-350;
  291.            nlines = 350;
  292.            break;
  293.        case 5:
  294.            rg.x.ax = 15;
  295.            maxm =  YBIT-350;
  296.            nlines = 350;
  297.            break;
  298.        case 7:
  299.        case 8:
  300.        case 11:
  301.        case 12:
  302.            rg.x.ax = 17;
  303.            maxm =  YBIT-480;
  304.            nlines = 480;
  305.            break;
  306.        case 30:
  307.            rg.x.ax = 18;
  308.            maxm = YBIT-480;
  309.            nlines = 480;
  310.            break;
  311.        default:
  312.            puts("Invalid display adapter - requires EGA, VGA, or MCGA.");
  313.            exit(1);
  314.     }
  315.     int86(16,&rg,&rg);
  316. }
  317.  
  318.  
  319. void
  320. drawbmap(mline)
  321. int mline;
  322. {
  323.  
  324.     register char *c;            /* pointer into v7[] */
  325.     unsigned char *q;
  326.     unsigned char far *sc;
  327.     register UNSIGN32 mask;        /* mask for single bit selection */
  328.     INT16 i,j,k,ybottom,ytop;
  329.  
  330.     if(first_picture){
  331.         first_picture = FALSE;
  332.         vgainit();
  333.     }
  334.     sc = (unsigned char far *)0xa0000000;
  335.  
  336.     ytop = YBIT-nlines-mline;
  337.     for (i = nlines-1; i >= 0; i--) {
  338.         q = (unsigned char *)BITMAP((ytop+i),0);
  339.         if(reversevideo){
  340.             for (j = 0; j < 80; j += 4, q += 4) {
  341.                *sc++ = q[3];
  342.                *sc++ = q[2];
  343.                *sc++ = q[1];
  344.                *sc++ = (*q);
  345.             }
  346.         }  else {
  347.             for (j = 0; j < 80; j += 4, q += 4) {
  348.                *sc++ = ~q[3];
  349.                *sc++ = ~q[2];
  350.                *sc++ = ~q[1];
  351.                *sc++ = ~(*q);
  352.             }
  353.         }
  354.     }
  355. }
  356.  
  357. /*-->unloadfonts*/
  358. /**********************************************************************/
  359. /***************************** unloadfonts ****************************/
  360. /**********************************************************************/
  361.  
  362. void
  363. unloadfonts()            /* mark all fonts as not loaded */
  364. {                /* and set no current fonts */
  365.  
  366.     for (fontptr = hfontptr; fontptr != (struct font_entry *)NULL;
  367.      fontptr = fontptr->next)
  368.     {
  369.     if (fontptr->font_file_id != (FILE*)NULL)
  370.     {
  371.         (void)fclose(fontptr->font_file_id);
  372.         fontptr->font_file_id = (FILE*)NULL;
  373.     }
  374.     }
  375.  
  376.     fontfp = (FILE*)NULL;        /* no current font file */
  377.     for ( ; nopen > 0; --nopen)        /* clear font file cache */
  378.     {
  379.     font_files[nopen].font_id = (FILE*)NULL;
  380.     font_files[nopen].use_count = (INT16)0;
  381.     }
  382.  
  383.  
  384. }
  385.  
  386.  
  387. vgasequence()            /* end-of-page action */
  388. {
  389.     UNSIGN32 oldrunmag;
  390.     firstlinepage = 0;
  391.     cur_index = 0;
  392.     neednewpage = 1;
  393.     newmagfact = (double)1.;
  394.  
  395.     while(1) {
  396.     neednewbmap = 0;    
  397.     if(!first_picture || (kbhit() != 0))collectkeys();
  398.  
  399.     if(neednewpage){
  400.         if(newmagfact != (double)1){
  401.             do{
  402.                 oldrunmag = runmag;
  403.                 runmag = MAGSIZE(actfact((UNSIGN32)
  404.                          ((double)runmag*newmagfact)));
  405.                 conv = ((float)num/(float)den) *
  406.                          ((float)runmag/(float)STDMAG) *
  407. #if    USEGLOBALMAG
  408.                         actfact(mag) *
  409. #endif
  410.                         ((float)RESOLUTION/254000.0);
  411.                 newmagfact = (double)1;
  412.                 unloadfonts();
  413.  
  414.  
  415. /* NB: It is important here that the loop index be global; the relation
  416.    of fontptr to pfontptr is used by openfont() to decide whether the font
  417.    file is already open. */
  418.  
  419.                 for (fontptr = hfontptr; fontptr != (struct font_entry *)NULL;
  420.                 fontptr = fontptr->next)
  421.                 {
  422.                 pfontptr = (struct font_entry *)(NULL);
  423.                                      /* so reldfont() calls openfont() */
  424.                 (void)reldfont(fontptr);
  425.                                        /* get new font metrics */
  426.                 if(kbhit())collectkeys();
  427.                 if(newmagfact != (double)1.) break;
  428.                 }
  429.             } while( newmagfact != (double)1);
  430.  
  431.         }
  432.         brokenprtpage = 0;
  433.         prtpage(page_ptr[cur_index]);
  434.         if(!brokenprtpage){
  435.             neednewpage = 0;
  436.             neednewbmap = 1;
  437.         }
  438.     }
  439.     if((!brokenprtpage) && neednewbmap)drawbmap(firstlinepage);
  440.     }
  441. }
  442.  
  443.  
  444.  
  445. collectkeys()
  446. {
  447.  
  448. unsigned   keyhit;
  449. unsigned   char tc, extend ;
  450. int        oldm, np;
  451.  
  452.  
  453.     do {
  454.  
  455.         tc = getch();
  456.  
  457.         if(tc == 0){
  458.             switch((int)getch()) {
  459.                 case 71:    /* home */
  460.                     if(cur_index != 0)neednewpage = 1;
  461.                     cur_index = 0;    
  462.                     firstlinepage = 0;
  463.                     break;
  464.                 case 79:    /* end */
  465.                     if(cur_index != page_count -1)neednewpage = 1;
  466.                     cur_index = page_count -1;    
  467.                     firstlinepage = 0;
  468.                     break;
  469.                 case 75:    /* left arrow */
  470.                     leftmargin -= (double)0.25;
  471.                     lmargin = (COORDINATE)(leftmargin*((float)XDPI));
  472.                     neednewpage = 1;
  473.                     break;
  474.                 case 77:    /* right arrow */
  475.                     leftmargin += (double)0.25;
  476.                     lmargin = (COORDINATE)(leftmargin*((float)XDPI));
  477.                     neednewpage = 1;
  478.                     break;
  479.                 case 81:    /* page down */
  480.                     if (cur_index < page_count -1){
  481.                         cur_index++;
  482.                         firstlinepage = 0;
  483.                         neednewpage = 1;
  484.                     }
  485.                     break;
  486.                 case 73:    /* page_up */
  487.                     if (cur_index > 0){
  488.                         cur_index--;
  489.                         firstlinepage = 0;
  490.                         neednewpage = 1;
  491.                     }
  492.                     break;
  493.                 case 72:    /* up arrow */
  494.                     firstlinepage -= 96;
  495.                     if(firstlinepage < MINM) firstlinepage = MINM;
  496.                     neednewbmap = 1;
  497.                     break;
  498.                 case 80:    /* down arrow */
  499.                     firstlinepage += 96;
  500.                     if(firstlinepage > maxm) firstlinepage = maxm;
  501.                     neednewbmap = 1;
  502.                     break;
  503.                 default:
  504.                     break;
  505.             }          
  506.         } else {
  507.             switch(tc) {
  508.               case 'q':        /* quit */
  509.             case 'Q':
  510.             case 'x':        /* exit */
  511.             case 'X':
  512.             case '\003':        /* CTL-C */
  513.             case '\031':        /* CTL-Y */
  514.                 (void)devterm();    /* terminate device output */
  515.                 (void)dviterm();    /* terminate DVI file processing */
  516.                 (void)alldone();    /* this does not return */
  517.                 case 'r':
  518.                     leftmargin += (double)0.25;
  519.                     lmargin = (COORDINATE)(leftmargin*((float)XDPI));
  520.                     neednewpage = 1;
  521.                     break;
  522.                 case 'R':
  523.                     leftmargin += (double)1.0;
  524.                     lmargin = (COORDINATE)(leftmargin*((float)XDPI));
  525.                     neednewpage = 1;
  526.                     break;
  527.                 case 'l':
  528.                     leftmargin -= (double)0.25;
  529.                     lmargin = (COORDINATE)(leftmargin*((float)XDPI));
  530.                     neednewpage = 1;
  531.                     break;
  532.                 case 'L':
  533.                     leftmargin -= (double)1.0;
  534.                     lmargin = (COORDINATE)(leftmargin*((float)XDPI));
  535.                     neednewpage = 1;
  536.                     break;
  537.                 case 'd':
  538.                     topmargin += (double)0.25;
  539.                     tmargin = (COORDINATE)(topmargin*((float)YDPI));
  540.                     neednewpage = 1;
  541.                     break;
  542.                 case 'D':
  543.                     topmargin += (double)1.0;
  544.                     tmargin = (COORDINATE)(topmargin*((float)YDPI));
  545.                     neednewpage = 1;
  546.                     break;
  547.                 case 'u':
  548.                     topmargin -= (double)0.25;
  549.                     tmargin = (COORDINATE)(topmargin*((float)YDPI));
  550.                     neednewpage = 1;
  551.                     break;
  552.                 case 'U':
  553.                     topmargin -= (double)1.0;
  554.                     tmargin = (COORDINATE)(topmargin*((float)YDPI));
  555.                     neednewpage = 1;
  556.                     break;
  557.                 case '\r':
  558.                 case '\n':         
  559.                     if (cur_index < page_count -1){
  560.                         cur_index++;
  561.                         firstlinepage = 0;
  562.                         neednewpage = 1;
  563.                     }
  564.                     break;
  565.                case '0':        /* goto n-th page */
  566.             case '1':
  567.             case '2':
  568.             case '3':
  569.             case '4':
  570.             case '5':
  571.             case '6':
  572.             case '7':
  573.             case '8':
  574.             case '9':
  575.                     oldm = cur_index;
  576.                 np = tc - 48;
  577.                     while(1) {
  578.                        while(!kbhit());
  579.                        tc = getch();
  580.                        if(tc == 0) (void)getch();
  581.                        else {
  582.                            if(tc == 27) goto escape;  
  583.                            if(tc == '\r') break;
  584.                            tc -= 48;
  585.                            if(tc >= 0 && tc <= 9) np = np*10 + tc;
  586.                        }
  587.                     }     
  588.                     if(np < 0) np = 0;
  589.                     if(np > page_count) np = page_count;
  590.                     cur_index = np - 1;
  591.                     if(oldm != cur_index) {
  592.                         firstlinepage = 0;
  593.                         neednewpage = 1;
  594.                     }
  595. escape:
  596.                     break;
  597.                 case 'b':
  598.                     newmagfact *= sqrt((double)1.2);
  599.                     neednewpage = 1;
  600.                     break;
  601.                 case 'B':
  602.                     newmagfact *= (double)1.2;
  603.                     neednewpage = 1;
  604.                     break;
  605.                 case 's':
  606.                     newmagfact /= sqrt((double)1.2);
  607.                     neednewpage = 1;
  608.                     break;
  609.                 case 'S':
  610.                     newmagfact /= (double)1.2;
  611.                     neednewpage = 1;
  612.                     break;
  613.                 default:
  614.                     break;
  615.             }
  616.         }
  617.     } while (kbhit());
  618. }
  619.